package 线程;

import java.util.concurrent.*;

/**
 * @author:谢君臣
 * @Date:2021/8/2-19:43
 * @version:1.0
 * @function:
 */
public class TestThread {
    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(10,
                10,
                0L,
                TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(100));
        Future futureTask = executor.submit(new Callable<String>() {
            @Override
            public String call() throws Exception {
                return "asdfasdf";
            }
        });
        String res = null;
        try {
            res = (String) futureTask.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        System.out.println(res);

        ThreadPoolExecutor executors = new ThreadPoolExecutor(10,
                10,
                0L,
                TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(10));
        Executor executor1 = executors;
        ThreadPoolExecutor executor2 = (ThreadPoolExecutor) executor1;
        Future<String> submit = executor2.submit(() -> {
            return "asdfasd";
        });
        try {
            String s = submit.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
